package com.shuai.shuaisecondhand_springboot.mapper;



import com.shuai.shuaisecondhand_springboot.entity.Collection;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CollectionMapper {

    //sql->根据用户id查询数据
    @Select("SELECT * FROM collection LEFT JOIN goods ON collection.Gid=goods.id  WHERE collection.Uid=#{Uid} AND (IFNULL(goods.name,'') LIKE concat('%', #{name}, '%')) ORDER BY collection.time DESC")
    List<Collection> findCollection(@Param("Uid") String Uid, @Param("name") String name);

    //sql->查询Sid所有数据量
    @Select("SELECT count(*) FROM collection LEFT JOIN goods ON collection.Gid=goods.id  WHERE collection.uid=#{Uid} AND (IFNULL(goods.name,'') LIKE concat('%', #{name}, '%'))")
    int getSidTotal(@Param("Uid") String Uid,@Param("name") String name);

    //sql->根据用户id和商品id查询数据
    @Select("SELECT * FROM collection WHERE Uid=#{Uid} AND Gid=#{Gid}")
    Boolean findMyCollection(@Param("Uid") String Uid,@Param("Gid") String Gid);

    //sql->插入
    @Insert("INSERT INTO collection(Uid,Gid) VALUES (#{Uid},#{Gid})")
    Boolean insertCollection(@Param("Uid") String Uid,@Param("Gid") String Gid);

    //sql->删除
    @Delete("DELETE FROM collection WHERE Uid=#{Uid} AND Gid=#{Gid}")
    Integer deleteCollection(@Param("Uid") long Uid,@Param("Gid") long Gid);
}
